<%--
  Created by IntelliJ IDEA.
  User: 31036
  Date: 2025/3/23
  Time: 23:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>充值</title>
    <script src="../../static/js/jquery-1.8.3.js"></script>
    <script>
        $(function () {
            getPark()
        })
//动态下拉
        function getPark() {
            $.ajax({
                url: "/park/getParkList",
                dataType: "json",
                success(res) {
                    $("#parkId").empty()
                    $("#parkId").append(`
                         <option value="">请选择</option>
                    `)
                    for (let x of res) {
                        $("#parkId").append(`
                         <option value="\${x.parkId}">\${x.parkName}</option>
                    `)

                    }
                }

            })
        }
    </script>
</head>
<body>
充值人 ： <input type="text" id="username" value="${user.username}" readonly><br>
充值金额: <input type="text" id="rechargeMoney"><br>
停车场: <select id="parkId">
    <option value="">请选择</option>
</select><br>

<input type="button" value="确定充值" onclick="addRecharge()">
</body>
<script>
    function addRecharge() {
        let rechargeMoney = $("#rechargeMoney").val();
        let parkId = $("#parkId").val();
        if (rechargeMoney < 0) {
            alert("金额有误")
            return;
        }

        if (!rechargeMoney || !parkId) {
            alert("金额停车场不能为空")
            return;
        }

        let obj = {rechargeMoney, parkId}
        $.ajax({
            url: "/recharge/addRecharge",
            type: "post",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(obj),
            dataType: "json",
            success(res) {
                if (res.code === 200) {
                    alert("新增充值成功，待审核")
                    location.href = "/sys/toRechargeList"
                }
                if (res.code === 100) {
                    alert(res.msg)
                }
            }

        })

    }
</script>
</html>
